package com.education.realtime.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

public class AtguiguUtil {
    public static String toDate(Long ts, String... format) {
        String f = "yyyy-MM-dd";
        if (format.length >= 1) {
            f = format[0];
        }
        return new SimpleDateFormat(f).format(ts);
    }

    public static <T> List<T> toList(Iterable<T> elements) {
        ArrayList<T> l = new ArrayList<>();
        for (T element : elements) {
            l.add(element);
        }
        return l;
    }

    public static long toTs(String today, String s) throws ParseException {
        return new SimpleDateFormat(s).parse(today).getTime();
    }

    //compareto比较时间大小，但是一定要到同一精度
    public static boolean compareLTZ(String currentTime, String lastTime) {
        String one = currentTime.replaceAll("Z", "");
        String two = lastTime.replaceAll("Z", "");

        int result = one.compareTo(two);
        return result >= 0;
    }
    public static String toDateTime(long ts, String... format) {
        String f = "yyyy-MM-dd HH:mm:ss";
        if (format.length >= 1) {
            f = format[0];
        }
        return new SimpleDateFormat(f).format(ts);
    }
}
